<template>
    <div>
        <div style="display: flex;justify-content: space-between; margin-top: 10px;margin-bottom: 10px">
            <el-button type="primary" icon="el-icon-plus"
                       @click="addshowBtn">添加工资账套
            </el-button>
            <el-button type="success" icon="el-icon-refresh" @click="initSalaries" circle></el-button>
        </div>
        <div>
            <el-table :data="salaries" :border="true" :stripe="true" max-height="680" size="small"
                      v-loading="loading"
                      element-loading-text="拼命加载中"
                      element-loading-spinner="el-icon-loading"
                      element-loading-background="rgba(255, 255, 255, 0.8)">
                <el-table-column type="selection" width="40"></el-table-column>
                <el-table-column prop="name"
                                 align="center"
                                 label="账套名称"
                                 width="150px">
                </el-table-column>
                <el-table-column prop="basicSalary"
                                 align="center"
                                 label="基本工资"
                                 width="110px">
                </el-table-column>
                <el-table-column prop="lunchSalary"
                                 align="center"
                                 label="通讯补助"
                                 width="100px">
                </el-table-column>
                <el-table-column prop="trafficSalary"
                                 align="center"
                                 label="交通补助"
                                 width="100px">
                </el-table-column>
                <el-table-column prop="bonus"
                                 align="center"
                                 label="奖金"
                                 width="100px">
                </el-table-column>
                <el-table-column prop="createDate"
                                 align="center"
                                 label="启用时间"
                                 width="100px">
                </el-table-column>
                <el-table-column label="住房公积金" align="center">
                    <el-table-column prop="pensionPer"
                                     align="center"
                                     label="住房公积金比率"
                                     width="140">
                    </el-table-column>
                    <el-table-column prop="pensionBase"
                                     align="center"
                                     label="住房公积金基数"
                                     width="150">
                    </el-table-column>
                </el-table-column>
                <el-table-column label="保险" align="center">
                    <el-table-column prop="medicalPer"
                                     align="center"
                                     label="保险比率"
                                     width="140">
                    </el-table-column>
                    <el-table-column prop="medicalBase"
                                     align="center"
                                     label="保险基金"
                                     width="150">
                    </el-table-column>
                </el-table-column>
                <el-table-column label="公司绩效金" align="center">
                    <el-table-column prop="moneyFundPer"
                                     align="center"
                                     label="绩效金比率"
                                     width="150">
                    </el-table-column>
                    <el-table-column prop="moneyFundBase"
                                     align="center"
                                     label="绩效金基金"
                                     width="150">
                    </el-table-column>
                </el-table-column>
                <el-table-column prop="realSalary"
                                 align="center"
                                 label="实际工资"
                                 width="150">
                </el-table-column>
                <el-table-column label="操作" fixed="right" min-width="208px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" round @click="showUpdateSalary(scope.row)">编辑</el-button>
                        <el-button type="danger" size="mini" round @click="deleteSalary(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div>
            <el-dialog
                    :title="dialogTitle"
                    :visible.sync="dialogVisible"
                    width="50%"
            >
                <div style="display: flex;justify-content: space-around;align-items: center">
                    <el-steps direction="vertical" :active="active">
                        <el-step :title="item" v-for="(item,index) in salaryItemName" :key="index"></el-step>
                    </el-steps>
                    <el-input style="width: 200px;" v-for="(value,title,index) in salary" type="text"
                              :placeholder="'请输入' + salaryItemName[index]"
                              v-model="salary[title]" v-show="active === index"
                              :key="index">
                    </el-input>
                </div>
                <span slot="footer" class="dialog-footer">
            <el-button @click="preStep">{{active==12?'取消':'上一步'}}</el-button>
            <el-button type="primary" @click="nextStep">{{active==11?'完成':'下一步'}}</el-button>
  </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    export default {
        name: "SalSob",
        data() {
            return {
                loading: false,
                dialogTitle: '添加账套',
                dialogVisible: false,
                salaries: [],
                active: 0,
                salaryItemName: [
                    '账套名称', '基本工资', '通讯补助', '交通补助', '奖金',
                    '住房公积金比率', '住房公积金基数', '保险比率', '保险基金', '绩效金比率', '绩效金基数', '实发工资'
                ],
                salary: {
                    name: '',
                    basicSalary: 0,
                    lunchSalary: 0,
                    trafficSalary: 0,
                    bonus: 0,
                    pensionPer: 0,
                    pensionBase: 0,
                    medicalPer: 0,
                    medicalBase: 0,
                    moneyFundPer: 0,
                    moneyFundBase: 0,
                    realSalary:this.basicSalary+this.bonus+this.lunchSalary+this.trafficSalary-this.pensionBase*this.pensionPer
                   -this.medicalBase*this.medicalPer+this.moneyFundBase*this.moneyFundPer
                }
            }
        },
        mounted() {
            this.initSalaries();
        },
        methods: {
            showUpdateSalary(data) {
                this.dialogTitle = '更新账套';
                this.active = 0;
                this.salary.id = data.id;
                this.salary.name = data.name;
                this.salary.basicSalary = data.basicSalary;
                this.salary.lunchSalary = data.lunchSalary;
                this.salary.trafficSalary = data.trafficSalary;
                this.salary.bonus = data.bonus;
                this.salary.pensionPer = data.pensionPer;
                this.salary.pensionBase = data.pensionBase;
                this.salary.medicalPer = data.medicalPer;
                this.salary.medicalBase = data.medicalBase;
                this.salary.moneyFundPer = data.moneyFundPer;
                this.salary.moneyFundBase = data.moneyFundBase;

                this.salary.realSalary = this.salary.basicSalary+this.salary.lunchSalary+this.salary.trafficSalary
                +this.salary.bonus-this.salary.pensionPer*this.salary.pensionBase-this.salary.medicalPer*this.salary.medicalBase
                +this.salary.moneyFundPer*this.salary.moneyFundBase;
                this.dialogVisible = true;

            },
            deleteSalary(data) {
                this.$confirm('此操作将永久删除该[' + data.name + ']账套, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.deleteRequest('/salary/sob/' + data.id).then(resp => {
                        if (resp) {
                            this.initSalaries();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            preStep() {
                if (this.active == 0) {
                    return;
                } else if (this.active == 11) {
                    this.dialogVisible = false;
                    return;
                }
                this.active--;
            },
            nextStep() {
                if (this.active == 11) {
                    if (this.salary.id) {
                        this.putRequest('/salary/sob/', this.salary).then(resp => {
                            if (resp) {
                                this.initSalaries();
                                this.dialogVisible = false;
                            }
                        })
                    } else {
                        this.postRequest('/salary/sob/', this.salary).then(resp => {
                            if (resp) {
                                this.initSalaries();
                                this.dialogVisible = false;
                            }
                        });
                    }
                    return;
                }
                this.active++;
            },
            addshowBtn() {
                this.dialogTitle = '添加账套';
                this.salary = {
                    name: '',
                    basicSalary: 0,
                    lunchSalary: 0,
                    trafficSalary: 0,
                    bonus: 0,
                    pensionPer: 0,
                    pensionBase: 0,
                    medicalPer: 0,
                    medicalBase: 0,
                    moneyFundPer: 0,
                    moneyFundBase: 0
                };
                this.active = 0;
                this.dialogVisible = true;
            },
            initSalaries() {
                this.loading = true
                this.getRequest('/salary/sob/').then(resp => {
                    if (resp) {
                        this.salaries = resp;
                        this.loading = false
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>